using System;
using System.Collections.Generic;
using Clandestine.Engines.Field;
using Qyoto;

namespace Shlick.LayerModel
{
	internal abstract class Item : QObject
	{	
		protected static Dictionary<LayerTreeMode, Dictionary<object, Item>> cachedItems = new Dictionary<LayerTreeMode, Dictionary<object, Item>>();
		public MapDocument MapDocument { get; private set; }
		public LayerTreeMode Mode { get; private set; }
		
		protected Item(object item, MapDocument mapDocument, LayerTreeMode mode)
		{
			this.MapDocument = mapDocument;
			this.Mode = mode;
			if (!cachedItems.ContainsKey(mode))
				cachedItems.Add(mode, new Dictionary<object, Item>());
			cachedItems[mode].Add(item, this);
		}
		
		// Get(object) can't be here as it needs to call a ctor, and we're abstract!
	
		// Gets the row of the parent's parent that the parent is in. -- QT is weird.
		public int ParentRow()
		{
			// Get parent
			Item parent = this.Parent();
			
			// Need to check if it's the root node.
			if (parent == null) // i.e. this is the root node
				return 0;
			else
				return parent.Row();
		}
	
		public virtual void ContextMenuRequested(LayerTreeView parent, QPoint pos)
		{
		}
		
		// Drag/drop flags
		public virtual uint Flags()
		{
			return (uint)(ItemFlag.ItemIsEnabled | ItemFlag.ItemIsSelectable);
		}
	
		public abstract int Row(); // gets the row of the item's parent that the item is in.
		public abstract Item Child(int row);
		public abstract Item Parent();
		public abstract int ChildrenCount();
		
		public abstract string GetData(); 
		public abstract string GetName();
		public virtual bool SetName(string name) { return false; } // bool for success
		public abstract bool? IsVisible(); // null if dont display anything!
		public virtual bool SetVisible(bool visible) { return false; } // bool for success
		
		public virtual int? GetDepth() // can return null if no depth info
		{
			return null;
		}
	}
	
}